<?php

class Pagination {

    //put your code here
    public function display($page, $total) {
        $pages = $total/PER_PAGE;
        
        $html = "<span id='span'><a herf='index.php?page=$page'> $page </a></span>";

        $count = 1;

        for ($i = 1; $i < PER_PAGE; $i ++) {
            if ($page + $i < $pages) {
                $li = $page + $i;
                $html .= "<span id='span'><a herf = 'index.php?page=$li'> $li </a></span>";
                $count++;
            }
            if ($count >= PER_PAGE)
                break;

            if ($page - $i > 0) {
                $li = $page - $i;
                $html = "<span id='span'><a herf = 'index.php?page=$li'> $li </a></span>" .$html;
                $count++;
            }
            if ($count >= PER_PAGE)
                break;
        }
        if ($page - 1 > 0) {
            $li = $page - 1;
            $html = "<a herf = 'index.php?page=$li'>PERV</a></span>" . $html;
        }
        if ($page + 1 < $pages) {
            $li = $page + 1;
            $html .= "<span id='span'><a herf = 'index.php?page=$li'> Next </a></span>";
        }
        if ($page != 1) {

            $html = "<span id='span'><a herf = 'index.php?page=1'>frist</a></span>" . $html;
        }
        if ($page != $pages) {

            $html = $html. "<span id='span'><a herf = 'index.php?page=$pages'>last</a></span>";
        }
        return $html;
    }

}
